package com.ys.controller.web.storage;

import com.bo.vo.L;
import com.bo.vo.W;
import com.ys.config.MenuId;
import com.ys.dto.SubGridConfigDto;
import com.ys.entity.storage.*;
import com.ys.service.storage.TccTransportationTypeService;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.Flow;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;

@Controller
@RequestMapping("/web/storage/tccTransportationType")
public class WebTccTransportationTypeController {

	@Autowired
	private CommonApiService<TccTransportationType> commonApiService;

	private final Long MENU_ID = MenuId.TCC_TransportationType;

	/*
	 * 新增
	 */

	@GetMapping("/toAdd")
	public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response){
		try {
			TccTransportationType entity = new TccTransportationType();
			entity.setStatus(1);

			// 子列表配置信息
			SubGridConfigDto subGridConfig = commonApiService.getSubGrid(MENU_ID, new ArrayList<Map<String, Object>>());
			return commonApiService.toAdd(model, entity, MENU_ID, null, subGridConfig);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}

	/*
	 * 修改
	 */

	@GetMapping("/toEdit")
	public String toEdit(Model model, HttpServletRequest request, HttpServletResponse response,
						 Long id){

		try {
			List<Map<String, Object>> sonlist = new TccTransportationTypeItem().setTransportationTypeId(id).queryMap();
			// 子列表配置信息
			SubGridConfigDto subGridConfig = commonApiService.getSubGrid(MENU_ID,sonlist);
			return commonApiService.toEdit(model, id, new TccTransportationType(), MENU_ID, null, subGridConfig);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}

}




